package com.dalin.platform.etl.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import com.dalin.common.base.BaseObject;
import com.dalin.platform.etl.condition.EtlColumnInfoCondition;
import com.dalin.platform.pub.PlatContext;
/*****************************************************************************
 * @content: 类信息                                                   *
 * @author : 那建林                                                                                                                                 *
 * @crtDate: 2010-05-11                                                     *
 * @modDate: 2010-05-11                                                     *
 * @version: 1.00                                                           *
 ****************************************************************************/
@Entity
@Table(name="ETL_TABLE_INFO")
public class EtlTableInfoEntity extends BaseObject {
    private Long tableId; // TABLE_ID,16,0
    private Long databaseId; // DATABASE_ID,16,0
    private String tableName; // TABLE_ENGLISH_NAME,128,0
    private String tableComment; // TABLE_CHINESE_NAME,256,0
    private String remark; // REMARK,256,0


	@Id
    @Column(name="TABLE_ID")
    @GeneratedValue(strategy = GenerationType.TABLE,generator="generator_normal")
    @TableGenerator(
        name = "generator_normal",
        table = "GLB_GENERATOR_KEY",
        pkColumnName = "GEN_KEY",
        valueColumnName = "GEN_VALUE",
        pkColumnValue = "ETL_TABLE_INFO",
        allocationSize=1
    )
    public Long getTableId() {
        return tableId;
    }

    public void setTableId(Long tableId) {
        this.tableId = tableId;
    }
    
    @Column(name="DATABASE_ID")
	public Long getDatabaseId() {
		return databaseId;
	}

	public void setDatabaseId(Long databaseId) {
		this.databaseId = databaseId;
	}
	
    @Column(name="TABLE_NAME")
	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

    @Column(name="TABLE_COMMENT")
	public String getTableComment() {
		return tableComment;
	}

	public void setTableComment(String tableComment) {
		this.tableComment = tableComment;
	}

    @Column(name="REMARK")
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    
    
    
    
    
    @Transient
    public List<EtlColumnInfoEntity> getEtlColumnInfoEntitys() {
    	EtlColumnInfoCondition cond = new EtlColumnInfoCondition();
    	cond.setTableId(this.getTableId());
		return PlatContext.getDao().queryObjsToPages(cond.prepareParams()
				.getPreparedPageQuery());
	}

	@Transient
    public EtlDatabaseInfoEntity getDatabaseInfoEntity() {
		return (EtlDatabaseInfoEntity) PlatContext.getDao()
				.findObjById(EtlDatabaseInfoEntity.class, this.getDatabaseId());
	}
    

	@Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof EtlTableInfoEntity)) return false;
        final EtlTableInfoEntity other = (EtlTableInfoEntity) o;
        if (tableId == null) {
            if (other.tableId != null) return false;
        } else if (!tableId.equals(other.tableId)) {
            return false;
        }
        if (databaseId == null) {
            if (other.databaseId != null) return false;
        } else if (!databaseId.equals(other.databaseId)) {
            return false;
        }
        if (tableName == null) {
            if (other.tableName != null) return false;
        } else if (!tableName.equals(other.tableName)) {
            return false;
        }
        if (tableComment == null) {
            if (other.tableComment != null) return false;
        } else if (!tableComment.equals(other.tableComment)) {
            return false;
        }
        if (remark == null) {
            if (other.remark != null) return false;
        } else if (!remark.equals(other.remark)) {
            return false;
        }
        return true;
    }

	
	public int hashCode() {
        int njlrst = 17;
        njlrst = 31 * njlrst + (tableId == null ? 0 : tableId.hashCode());
        njlrst = 31 * njlrst + (databaseId == null ? 0 : databaseId.hashCode());
        njlrst = 31 * njlrst + (tableName == null ? 0 : tableName.hashCode());
        njlrst = 31 * njlrst + (tableComment == null ? 0 : tableComment.hashCode());
        njlrst = 31 * njlrst + (remark == null ? 0 : remark.hashCode());
        return njlrst;
    }
}
